package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Strategy;
import cn.wolfcode.luowowo.article.mapper.StrategyMapper;
import cn.wolfcode.luowowo.article.service.IStrategyService;
import cn.wolfcode.luowowo.common.query.StrategyQueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class StrategyServiceImpl implements IStrategyService {
    @Autowired
    private StrategyMapper strategyMapper;
    public PageInfo query(StrategyQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> list = strategyMapper.queryForList(qo);
        return new PageInfo(list);
    }

    public void saveOrUpdate(Strategy strategy) {
        if(strategy.getId() == null){
            //添加
            strategyMapper.insert(strategy);
        }else{
            //修改
            strategyMapper.updateByPrimaryKey(strategy);
        }
    }

    public void deleteById(Long id) {
        strategyMapper.deleteByPrimaryKey(id);
    }

    public List<Strategy> selectAllStrategy() {
        return strategyMapper.selectAll();
    }
}
